<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
define('NOSESSION',true);
require_once '../core/core.php';
define('NO_ERROR_RETURN',true);
if($_AR['close']){
	exi('站点已关闭','error');
}

if($_RQ['op']=='test'){
	//发起授权体验地址
	$authurl = cfc('open')->get_sq_url(1);
	echo '<a href="'.$authurl.'%26test=1"><img src="https://open.weixin.qq.com/zh_CN/htmledition/res/assets/res-design-download/icon_button3_2.png" /></a>';
}
if($_RQ['op']=='ticket'){
	//接收开放平台推送的 ticket
	$open=core_setting('open');
	$post=file_get_contents('php://input');
	require ROOT_D.'/core/library/aes/wxBizMsgCrypt.php';
	$pc = new WXBizMsgCrypt($open['token'], $open['key'], $open['appid']);
	$msg = '';
	$errCode = $pc->decryptMsg($_RQ['msg_signature'],$_RQ['timestamp'], $_RQ['nonce'], $post, $msg);
	$msg=xml2array($msg);
	if($msg['InfoType']=='component_verify_ticket'){
		$open['ticket']=$msg['ComponentVerifyTicket'];
		core_setting('open',$open);
		exit('success');
	}
	exit('fail');
}

exit('error op');